package cn.cvs.utils;

import org.apache.commons.io.FilenameUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * 文件工具类
 */
public class FileUtils {
    //判断是否为图片
    public static boolean checkImage(String fileName){
        if (fileName.lastIndexOf(".")>0){
            boolean flag = false;
            String []exts={"jpg","png","jpeg","peng"};
            //获取文件的后缀
            String ext = FilenameUtils.getExtension(fileName);
            for (String temp : exts) {
                if (temp.equalsIgnoreCase(ext)){
                    flag=true;
                    break;
                }
            }

            return flag;
        }else {
            return false;
        }
    }


    //根据文件名，生成一个新文件名
    public static String newFileNmae(String oldFileNmae){
        String ext = FilenameUtils.getExtension(oldFileNmae);
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String time = format.format(new Date());
        Random random = new Random();
        return time+"_"+random.nextInt(10000000)+"_Personal."+ext;
    }

}
